<?php

namespace app\models\search;

use app\models\AuthItem;
use mdm\admin\components\Configs;
use Yii;
use yii\data\ActiveDataProvider;
use yii\data\ArrayDataProvider;
use yii\rbac\Item;

class AuthItemSearch extends \mdm\admin\models\searchs\Assignment
{
    const TYPE_ROUTE = 101;
    public $name;
    public $type;
    public $description;
    public $ruleName;
    public $data;

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name', 'ruleName', 'description'], 'safe'],
            [['type'], 'integer'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'name' => Yii::t('rbac-admin', 'Name'),
            'item_name' => Yii::t('rbac-admin', 'Name'),
            'type' => Yii::t('rbac-admin', 'Type'),
            'description' => Yii::t('rbac-admin', 'Description'),
            'ruleName' => Yii::t('rbac-admin', 'Rule Name'),
            'data' => Yii::t('rbac-admin', 'Data'),
        ];
    }

    public function search($params, $class=null, $usernameField=null)
    {
        $query = AuthItem::find();
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);
        //设置前端传来的需要查询的数据
        $this->load($params,"AuthItemSearch");
        if (!$this->validate()) {
            return $dataProvider;
        }
        $query->andFilterWhere(['=', 'type', $this->type]);

        return $dataProvider;
    }
}
